package com.nbsaas.boot;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class TimeRangeCalculator1 {

    public static void main(String[] args) {
        for (int i = 1; i < 6; i++) {
            List<LocalDateTime> timeRange = getTimeRange(i);
            for (LocalDateTime dateTime : timeRange) {
                System.out.println(dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            }
        }


        // 同样的方式可以应用于其他参数
    }

    public static List<LocalDateTime> getTimeRange(int param) {
        LocalDateTime now = LocalDateTime.now();
        List<LocalDateTime> result = new ArrayList<>();

        switch (param) {
            case 1:
                result.add(now.withHour(0).withMinute(0).withSecond(0));
                result.add(now.withHour(23).withMinute(59).withSecond(59));
                break;
            case 2:
                result.add(now.with(now.toLocalDate().with(java.time.DayOfWeek.MONDAY)).withHour(0).withMinute(0).withSecond(0));
                result.add(now.with(now.toLocalDate().with(java.time.DayOfWeek.SUNDAY)).withHour(23).withMinute(59).withSecond(59));
                break;
            case 3:
                result.add(now.with(now.toLocalDate().withDayOfMonth(1)).withHour(0).withMinute(0).withSecond(0));
                result.add(now.with(now.toLocalDate().plusMonths(1).withDayOfMonth(1)).withHour(23).withMinute(59).withSecond(59));
                break;
            case 4:
                int currentMonth = now.getMonthValue();
                int quarterStartMonth = (currentMonth - 1) / 3 * 3 + 1;
                result.add(now.with(now.toLocalDate().withMonth(quarterStartMonth).withDayOfMonth(1)).withHour(0).withMinute(0).withSecond(0));
                result.add(now.with(now.toLocalDate().withMonth(quarterStartMonth + 2).withDayOfMonth(1).plusMonths(1).minusDays(1)).withHour(23).withMinute(59).withSecond(59));
                break;
            case 5:
                result.add(now.with(now.toLocalDate().withDayOfYear(1)).withHour(0).withMinute(0).withSecond(0));
                result.add(now.with(now.toLocalDate().plusYears(1).withDayOfYear(1).minusDays(1)).withHour(23).withMinute(59).withSecond(59));
                break;
            default:
                // 处理无效参数的逻辑
                break;
        }

        return result;
    }
}
